package com.ruoyi.web.controller.system;

import java.util.List;

import com.ruoyi.system.domain.TExamRoom;
import com.ruoyi.system.domain.TExamSite;
import com.ruoyi.system.service.ITExamRoomService;
import com.ruoyi.system.service.ITExamSiteService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TExamWorkUser;
import com.ruoyi.system.service.ITExamWorkUserService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

import javax.annotation.Resource;

/**
 * 考试工作人员Controller
 *
 * @author ruoyi
 * @date 2021-03-02
 */
@Controller
@RequestMapping("/system/workuser")
public class TExamWorkUserController extends BaseController
{
    private String prefix = "system/workuser";

    @Autowired
    private ITExamWorkUserService tExamWorkUserService;

    @Resource
    private ITExamRoomService tExamRoomService;

    @Resource
    private ITExamSiteService examSiteService;

    @RequiresPermissions("system:workuser:view")
    @GetMapping()
    public String user()
    {
        return prefix + "/user";
    }

    /**
     * 查询考试工作人员列表
     */
    @RequiresPermissions("system:workuser:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TExamWorkUser tExamWorkUser)
    {
        startPage();
        List<TExamWorkUser> list = tExamWorkUserService.selectTExamWorkUserList(tExamWorkUser);
        return getDataTable(list);
    }

    /**
     * 导出考试工作人员列表
     */
    @RequiresPermissions("system:workuser:export")
    @Log(title = "考试工作人员", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TExamWorkUser tExamWorkUser)
    {
        List<TExamWorkUser> list = tExamWorkUserService.selectTExamWorkUserList(tExamWorkUser);
        ExcelUtil<TExamWorkUser> util = new ExcelUtil<TExamWorkUser>(TExamWorkUser.class);
        return util.exportExcel(list, "user");
    }

    /**
     * 新增考试工作人员
     */
    @GetMapping("/add")
    public String add(ModelMap mmp)
    {
        List<TExamSite> sites = examSiteService.selectTExamSiteList(new TExamSite());
        List<TExamRoom> rooms = tExamRoomService.selectTExamRoomList(new TExamRoom());
        mmp.put("sites",sites);
        mmp.put("rooms",rooms);
        return prefix + "/add";
    }

    /**
     * 新增保存考试工作人员
     */
    @RequiresPermissions("system:workuser:add")
    @Log(title = "考试工作人员", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TExamWorkUser tExamWorkUser)
    {
        return toAjax(tExamWorkUserService.insertTExamWorkUser(tExamWorkUser));
    }

    /**
     * 修改考试工作人员
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TExamWorkUser tExamWorkUser = tExamWorkUserService.selectTExamWorkUserById(id);
        mmap.put("tExamWorkUser", tExamWorkUser);
        return prefix + "/edit";
    }

    /**
     * 修改保存考试工作人员
     */
    @RequiresPermissions("system:workuser:edit")
    @Log(title = "考试工作人员", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TExamWorkUser tExamWorkUser)
    {
        return toAjax(tExamWorkUserService.updateTExamWorkUser(tExamWorkUser));
    }

    /**
     * 删除考试工作人员
     */
    @RequiresPermissions("system:workuser:remove")
    @Log(title = "考试工作人员", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tExamWorkUserService.deleteTExamWorkUserByIds(ids));
    }

    /**
     * 选择考试工作人员
     */
    @GetMapping("/selectUser")
    public String selectUser(ModelMap mmap)
    {
        return prefix + "/selectUser";
    }

}
